﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Data;
using PickingBusiness;

namespace Infrastructure.Util
{
    public class ConfigInfo
    {
        public static string LineCodeA = "Line1";
        public static string LineCodeB = "Line2";
        public static string LineCodeC = "Line3";

        public static int MaxWorkerCount1 = 0;
        public static int MinWorkerCount1 = 1;
        public static int MaxLightAddress1 = 0;
        public static int MinLightAddress1 = 0;
        public static string IsPrint1 = "T";
        public static string LineName1 = string.Empty;
        public static string LineCode1 = string.Empty;

        public static int MaxWorkerCount2 = 0;
        public static int MinWorkerCount2 = 1;
        public static int MaxLightAddress2 = 0;
        public static int MinLightAddress2 = 0;
        public static string IsPrint2 = "T";
        public static string LineName2 = string.Empty;
        public static string LineCode2 = string.Empty;

        public static int MaxWorkerCount3 = 0;
        public static int MinWorkerCount3 = 1;
        public static int MaxLightAddress3 = 0;
        public static int MinLightAddress3 = 0;
        public static string IsPrint3 = "T";
        public static string LineName3 = string.Empty;
        public static string LineCode3 = string.Empty;

        public static string CmdLEDGreenLine1 = "8001";
        //public static string CmdLEDYellowLine1 = "8002";
        public static string CmdLEDRedLine1 = "8003";
        //public static string CmdLEDBeepLine1 = "8004";
        public static string CmdLEDBeep0Line1 = "8002";
        public static string CmdLEDBeep1Line1 = "8003";
        public static string CmdLEDBeep2Line1 = "8004";

        public static string CmdLEDGreenLine2 = "8001";
        //public static string CmdLEDYellowLine2 = "8002";
        public static string CmdLEDRedLine2 = "8003";
        //public static string CmdLEDBeepLine2 = "8004";

        public static string CmdLEDBeep0Line2 = "8002";
        public static string CmdLEDBeep1Line2 = "8003";
        public static string CmdLEDBeep2Line2 = "8004";

        public static string CmdLEDGreenLine3 = "8001";
        //public static string CmdLEDYellowLine3 = "8002";
        public static string CmdLEDRedLine3 = "8003";
        //public static string CmdLEDBeepLine3 = "8004";

        public static string CmdLEDBeep0Line3 = "8002";
        public static string CmdLEDBeep1Line3 = "8003";
        public static string CmdLEDBeep2Line3 = "8004";

        public static string AxAiPlugIpAddress1 = string.Empty;
        public static short AxAiPlugPort1 = 0;
        public static string AxAiPlugIpAddress2 = string.Empty;
        public static short AxAiPlugPort2 = 0;
        public static string AxAiPlugIpAddress3 = string.Empty;
        public static short AxAiPlugPort3 = 0;

        public static int LightNumInOneCommand = 10;

        public static void InitConfigInfo()
        {
            InitConfigInfo1();
            InitConfigInfo2();
            InitConfigInfo3();
        }

        public static void InitConfigInfo1()
        {
            AxAiPlugIpAddress1 = ConfigurationManager.AppSettings["AxAiPlugIpAddress1"].ToString().Trim();
            AxAiPlugPort1 = short.Parse(ConfigurationManager.AppSettings["AxAiPlugPort1"].ToString().Trim());

            CmdLEDGreenLine1 = ConfigurationManager.AppSettings["CmdLEDGreenLine1"].ToString().Trim();
            //CmdLEDYellowLine1 = ConfigurationManager.AppSettings["CmdLEDYellowLine1"].ToString().Trim();
            CmdLEDRedLine1 = ConfigurationManager.AppSettings["CmdLEDRedLine1"].ToString().Trim();
            //CmdLEDBeepLine1 = ConfigurationManager.AppSettings["CmdLEDBeepLine1"].ToString().Trim();
            CmdLEDBeep0Line1 = ConfigurationManager.AppSettings["CmdLEDBeep0Line1"].ToString().Trim();
            CmdLEDBeep1Line1 = ConfigurationManager.AppSettings["CmdLEDBeep1Line1"].ToString().Trim();
            CmdLEDBeep2Line1 = ConfigurationManager.AppSettings["CmdLEDBeep2Line1"].ToString().Trim();

            string lightNum = ConfigurationManager.AppSettings["LightNumInOneCommand"].ToString().Trim();

            int lightNumTemp = 0;

            if (int.TryParse(lightNum, out lightNumTemp))
            {
                if (lightNumTemp > 0)
                {
                    LightNumInOneCommand = lightNumTemp;
                }
            }

            DataRow row = PickingBusiness.Configuration.GetCurrentUseParameters(ConfigInfo.LineCodeA);

            LineName1 = row["Line_Name"].ToString();
            LineCode1 = row["Line_No"].ToString();
            IsPrint1 = row["IsPrint"].ToString();

            string workerCount = row["Picking_Worker_No"].ToString();
            string maxAddressNo = row["Max_Address_No"].ToString();
            string minAddressNo = row["Min_Address_No"].ToString();

            int workerCountTemp = 0;
            int maxLightAddressTemp = 0;
            int minLightAddressTemp = 0;

            if (int.TryParse(workerCount, out workerCountTemp))
            {
                MaxWorkerCount1 = workerCountTemp;
            }

            if (int.TryParse(maxAddressNo, out maxLightAddressTemp))
            {
                MaxLightAddress1 = maxLightAddressTemp;
            }

            if (int.TryParse(minAddressNo, out minLightAddressTemp))
            {
                MinLightAddress1 = minLightAddressTemp;
            }
        }

        public static void InitConfigInfo2()
        {
            AxAiPlugIpAddress2 = ConfigurationManager.AppSettings["AxAiPlugIpAddress2"].ToString().Trim();
            AxAiPlugPort2 = short.Parse(ConfigurationManager.AppSettings["AxAiPlugPort2"].ToString().Trim());

            CmdLEDGreenLine2 = ConfigurationManager.AppSettings["CmdLEDGreenLine2"].ToString().Trim();
            //CmdLEDYellowLine2 = ConfigurationManager.AppSettings["CmdLEDYellowLine2"].ToString().Trim();
            CmdLEDRedLine2 = ConfigurationManager.AppSettings["CmdLEDRedLine2"].ToString().Trim();
            //CmdLEDBeepLine2 = ConfigurationManager.AppSettings["CmdLEDBeepLine2"].ToString().Trim();

            CmdLEDBeep0Line1 = ConfigurationManager.AppSettings["CmdLEDBeep0Line2"].ToString().Trim();
            CmdLEDBeep1Line1 = ConfigurationManager.AppSettings["CmdLEDBeep1Line2"].ToString().Trim();
            CmdLEDBeep2Line1 = ConfigurationManager.AppSettings["CmdLEDBeep2Line2"].ToString().Trim();

            string lightNum = ConfigurationManager.AppSettings["LightNumInOneCommand"].ToString().Trim();

            int lightNumTemp = 0;

            if (int.TryParse(lightNum, out lightNumTemp))
            {
                if (lightNumTemp > 0)
                {
                    LightNumInOneCommand = lightNumTemp;
                }
            }

            DataRow row = PickingBusiness.Configuration.GetCurrentUseParameters(ConfigInfo.LineCodeB);

            LineName2 = row["Line_Name"].ToString();
            LineCode2 = row["Line_No"].ToString();
            IsPrint2 = row["IsPrint"].ToString();

            string workerCount = row["Picking_Worker_No"].ToString();
            string maxAddressNo = row["Max_Address_No"].ToString();
            string minAddressNo = row["Min_Address_No"].ToString();

            int workerCountTemp = 0;
            int maxLightAddressTemp = 0;
            int minLightAddressTemp = 0;

            if (int.TryParse(workerCount, out workerCountTemp))
            {
                MaxWorkerCount2 = workerCountTemp;
            }

            if (int.TryParse(maxAddressNo, out maxLightAddressTemp))
            {
                MaxLightAddress2 = maxLightAddressTemp;
            }

            if (int.TryParse(minAddressNo, out minLightAddressTemp))
            {
                MinLightAddress2 = minLightAddressTemp;
            }
        }

        public static void InitConfigInfo3()
        {
            AxAiPlugIpAddress3 = ConfigurationManager.AppSettings["AxAiPlugIpAddress3"].ToString().Trim();
            AxAiPlugPort3 = short.Parse(ConfigurationManager.AppSettings["AxAiPlugPort3"].ToString().Trim());

            CmdLEDGreenLine3 = ConfigurationManager.AppSettings["CmdLEDGreenLine3"].ToString().Trim();
            //CmdLEDYellowLine3 = ConfigurationManager.AppSettings["CmdLEDYellowLine3"].ToString().Trim();
            CmdLEDRedLine3 = ConfigurationManager.AppSettings["CmdLEDRedLine3"].ToString().Trim();
            //CmdLEDBeepLine3 = ConfigurationManager.AppSettings["CmdLEDBeepLine3"].ToString().Trim();

            CmdLEDBeep0Line1 = ConfigurationManager.AppSettings["CmdLEDBeep0Line3"].ToString().Trim();
            CmdLEDBeep1Line1 = ConfigurationManager.AppSettings["CmdLEDBeep1Line3"].ToString().Trim();
            CmdLEDBeep2Line1 = ConfigurationManager.AppSettings["CmdLEDBeep2Line3"].ToString().Trim();

            string lightNum = ConfigurationManager.AppSettings["LightNumInOneCommand"].ToString().Trim();

            int lightNumTemp = 0;

            if (int.TryParse(lightNum, out lightNumTemp))
            {
                if (lightNumTemp > 0)
                {
                    LightNumInOneCommand = lightNumTemp;
                }
            }

            DataRow row = PickingBusiness.Configuration.GetCurrentUseParameters(ConfigInfo.LineCodeC);

            LineName3 = row["Line_Name"].ToString();
            LineCode3 = row["Line_No"].ToString();
            IsPrint3 = row["IsPrint"].ToString();

            string workerCount = row["Picking_Worker_No"].ToString();
            string maxAddressNo = row["Max_Address_No"].ToString();
            string minAddressNo = row["Min_Address_No"].ToString();

            int workerCountTemp = 0;
            int maxLightAddressTemp = 0;
            int minLightAddressTemp = 0;

            if (int.TryParse(workerCount, out workerCountTemp))
            {
                MaxWorkerCount3 = workerCountTemp;
            }

            if (int.TryParse(maxAddressNo, out maxLightAddressTemp))
            {
                MaxLightAddress3 = maxLightAddressTemp;
            }

            if (int.TryParse(minAddressNo, out minLightAddressTemp))
            {
                MinLightAddress3 = minLightAddressTemp;
            }
        }
    }
}